<?php
    include 'base.php';

    $username = $_POST['username'];
    $password = $_POST['password'];

    $sql = "SELECT * FROM `user` WHERE username='$username'";

    $res = $conn -> query($sql);

    $row = mysqli_fetch_assoc($res);

    if ($row) {
        echo json_encode(array(
            "msg" => '用户名已存在',
            "status" => false
        ));
    } else {
        $sql2 = "INSERT INTO `user`(`username`, `password`) VALUES ('$username','$password')";
        $res2 = $conn -> query($sql2);

        if ($res2) {
            echo json_encode(array(
                "msg" => '注册成功',
                "status" => true
            ));
        }
    }
?>